<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>
    <!--  -->
    <FilterTable
      ref="table"
      :columns="columns"
      selectionType="single"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button type="primary" :disabled="isDisabled" @click="closeDrawer(2)">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { options } from '@/api/omSaleP/vehicleParameters/RebateManage/RebateRulesSet';
//import { vehicleConfiguration } from '@/api/omSaleP/vehicleParameters';

export default {
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: options,
      fetchParams: {},
      formData: {},
      isDisabled: true
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    async getList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find(item => item.fieldName === 'vehicleInfo').itemList = res.data;
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectChangeHandle(rows) {
      if (rows.length > 0) {
        this.isDisabled = false;
        this.tableList = JSON.parse(JSON.stringify(rows));
        return;
      }
      this.isDisabled = true;
    },

    closeDrawer(type) {
      if (type == 1) {
        return this.$emit('close', false);
      }
      if (type == 2) {
        return this.$emit('close', false, this.tableList);
      }
    },
    createdFrom() {
      return [
         {
          type: 'SELECT',
          label: '车系名称',
          fieldName: 'seriesId',
          placeholder: '请选择...',
          itemList: [],
          change: val => {
              this.changeBrandModelId(val)
          }
        },
        
        // {
        //   type: 'INPUT_CASCADER',
        //   label: '车型选择',
        //   fieldName: 'vehicleInfo',
        //   placeholder: '请选择',
        //   options: { titles: ['品牌', '车系', '车型', '配置', '选装'] },
        //   itemList: []
        // },
           {
            type: 'INPUT',
            label: '车型名称',
            fieldName: 'modelName',
            placeholder: '请输入标题名称...'
          },
         {
          type: 'INPUT',
          label: '配置名称',
          fieldName: 'configName',
          placeholder: '请输入...',
          maxlength:64,
        },
        {
          type: 'INPUT',
          label: '选装代码',
          fieldName: 'optionCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '选装名称',
          fieldName: 'optionName',
          placeholder: '请输入...',
          maxlength:64,
        },
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          initialValue: '',
          placeholder: '请输入',
          
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        {
          title: '选装代码',
          dataIndex: 'optionCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌名称',
          dataIndex: 'brandName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'configName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '市场指导价',
          dataIndex: 'referPrice',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
      ];
    }
  }
};
</script>
